<template>
  <div v-if="flag" class="task">
    <!-- <router-view></router-view> -->
    <template>
      <taskType v-if="urlType==='taskType'" />
      <taskList v-if="urlType==='taskList'" />
      <taskAction v-if="urlType==='taskAction'" />
      <taskNotice v-if="urlType==='taskNotice'" />
    </template>
  </div>
</template>

<script>
import { getTenantId, getTypeCodeList, getDictType } from '@/api/portalTaskUi/taskList'
import taskType from './taskType/index'
import taskList from './taskList/index'
import taskAction from './taskAction/index'
import taskNotice from './taskNotice/index'
export default {
  name: 'TaskUi',
  components: {
    taskType,
    taskList,
    taskAction,
    taskNotice
  },
  data() {
    return {
      code: [
        11001,
        11002,
        10000,
        11000,
        12000,
        12001,
        12002,
        12100,
        12200,
        13000
      ],
      flag: false
    }
  },
  computed: {
    urlType() {
      const { urlType } = this.$route.query
      return urlType
    }
  },
  async created() {
    console.log('xxxx')
    const data = await this.getTenantIdFun() // 获取用户id
    if (this.code.includes(data.code)) {
      return
    }
    this.$store.commit('setUser', data)
    const typeCodeData = await this.getTypeCodeListFun() // 获取租户名称字典
    const getDictTypeData = await this.getDictTypeFun('task_show_type') // 设置类型字典
    const targetTypeOptions = typeCodeData.map(v => {
      v.value = v.id
      v.label = v.name
      return v
    })
    console.log(targetTypeOptions)
    this.$store.commit('setUser', data)
    this.$store.commit('setTaskShowTypeOption', getDictTypeData)
    this.$store.commit('setTypeOptions', targetTypeOptions)
    this.flag = true
  },
  methods: {
    // 租户名称字典
    getTypeCodeListFun() {
      return new Promise(resolve => {
        getTypeCodeList().then(res => {
          console.log(res)
          resolve(res.data.data)
        })
      })
    },
    // 获取类型的字典
    getDictTypeFun(params) {
      // 字典名称
      return new Promise(resolve => {
        getDictType(params).then(res => {
          resolve(res.data.data)
        })
      })
    },
    // 获取用户身份
    getTenantIdFun() {
      return new Promise(resolve => {
        getTenantId().then(res => {
          resolve(res.data.data)
        })
      })
    }
  }
}
</script>

<style lang="less" scoped>
.task {
  width: 100%;
  height: 100%;
  background: #ffffff;
}
</style>
